package com.coolingme;

import java.io.IOException;

/**
 * 获取文件路径
 *
 * @author wangyue
 * @date 2020/10/26 9:33
 */
public class App {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        Test test = new Test();
        try {
            test.getResource();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}

class Test {
    public void getResource() throws IOException {
        System.out.println("获取项目地址：" + System.getProperty("user.dir"));
        System.out.println("获取当前文件路径：" + this.getClass().getResource(""));
        System.out.println("获取当前文件根路径：" + this.getClass().getResource("/"));
        System.out.println("获取当前文件根路径：" + this.getClass().getClassLoader().getResources(""));
        System.out.println("获取当前文件路径(只显示到\"/com/coolingme\")：" + this.getClass().getResource("/com/coolingme"));
        System.out.println("获取当前文件路径(去掉file)：" + this.getClass().getResource("").getPath());

    }
}
